using Godot;
using System;

namespace CurrentGame.NPC;


public partial class ShadeParticleEmitter : Node
{
    [Export]
    public PackedScene TeleportBeginParticle;
    [Export]
    public PackedScene TeleportEndParticle;


    // Node references
    private int _pidIterator = 0;
    private ShadeCharacter _shade;
    private Node _particleLayer;

    public override void _Ready()
    {
        _shade = GetNode<ShadeCharacter>("..");
        _particleLayer = GetNode<NodeReferenceMap>(Constants.NodeRefMapPath).ParticleLayer;
    }

    // Private functions
    private void CreateParticle(PackedScene scene)
    {
        var particle = scene.Instantiate<SelfFreeParticle>();
        particle.GlobalPosition = _shade.GlobalPosition;
        particle.Scale = _shade.Scale;
        particle.ParticleID = _pidIterator++;
        _particleLayer.AddChild(particle);
        particle.Emitting = true;
    }
    
    // Export interfaces
    public void CreateTeleportBeginParticle()
    {
        CreateParticle(TeleportBeginParticle);
    }

    public void CreateTeleportEndParticle()
    {
        CreateParticle(TeleportEndParticle);
    }
}
